from django.shortcuts import render, redirect
from django.urls import reverse
from .models import *
from django.http.response import JsonResponse

# Create your views here.
from django.http import HttpResponse

def tologin(request):
    return render(request,'login.html')

def login(request):
    u = request.POST.get('user')
    a = request.POST.get('account')
    p = request.POST.get('pwd')
    if u and p and a:
        c = mendb.objects.filter(name=u,account=a ,pwd=p).count()
        if c > 0:
            # Mens = mendb.objects.get(name=u,account=a,pwd=p)
            # request.session['Mens.id'] = Mens.id
            # return reverse('eyes/homepage')
            return render(request,"temporary interface/delayed_redirect4.html")
        else:
            return render(request,"temporary interface/delayed_redirect5.html")
    else:
        return render(request,"temporary interface/delayed_redirect6.html")

def toregister(request):
    return render(request,'register.html')

def register(request):
    u = request.POST.get('user')
    a = request.POST.get('account')
    p = request.POST.get('pwd')
    if u and p and a:
       a = request.POST.get('account')
       m = mendb.objects.filter(account=a).count()
       if m > 0:
        # return HttpResponse("Man")
           return render(request, 'temporary interface/delayed_redirect1.html')
       else:
           u = request.POST.get('user')
           a = request.POST.get('account')
           p = request.POST.get('pwd')
           man = mendb(name=u,account=a,pwd=p)
           man.save()
    else:
        return render(request,'temporary interface/delayed_redirect2.html')

    return render(request,"temporary interface/delayed_redirect3.html")


def index(request):
    return render(request,'index.html')




